;(function () {
  // 向上滚动效果
  function rollTable(type, time, direction) {
    var item = $('#' + type)
    if (!item) return
    item.liMarqueeDestroy()
    item.liMarquee({
      direction: direction || 'up',
      scrollamount: time || 20,
      runshort: false, // 内容不足时是否滚动
      circular: false, //是否无缝滚动
      drag: false,
    })
  }

  function formatDecimal(num, decimal) {
    if (!num) return ''
    if (+num % 1 === 0) return num
    num = num.toString()
    let index = num.indexOf('.')
    num =
      index !== -1 ? num.substring(0, decimal + index + 1) : num.substring(0)
    var res = parseFloat(num).toFixed(decimal)
    return res[res.length - 1] === '0' ? (+res).toFixed(1) : res
  }

  function getCurrentTime() {
    var time = new Date()
    var year = time.getFullYear()
    var month = time.getMonth() + 1
    var day = time.getDate()
    var hour = time.getHours()
    var minute = time.getMinutes()
    var second = time.getSeconds()
    var currentTime =
      year +
      '-' +
      (month > 9 ? month : '0' + month) +
      '-' +
      (day > 9 ? day : '0' + day) +
      ' ' +
      (hour > 9 ? hour : '0' + hour) +
      ':' +
      (minute > 9 ? minute : '0' + minute) +
      ':' +
      (second > 9 ? second : '0' + second)
    return currentTime
  }
  getCurrentTime()

  function getMd5(val) {
    return CryptoJS.MD5(val) + ''
  }

  var APP_KEY = 'a7b68ff412a42297784a09c5e5f5d983'
  var APP_ACTION = 'data_find'
  var APP_SECRET = '698f56acd2f80a66584486333a335a44'

  function _post(name, data,resolve, reject) {
    var currentTime = getCurrentTime()
    var params = {
      action: APP_ACTION,
      name: name,
      rows: 5000,
    }
    $.ajax({
      url: window.baseUrl + 'admin/databoard/xuGetData',
      type: 'GET',
      dataType:'json',
      data: params,
      success: function (res) {
        console.log(res)
        resolve && resolve(res)
      },
      error: function (err) {
        console.log(err)
        reject && reject(err)
      },
    })
  }

  window.rollTable = rollTable
  window.formatDecimal = formatDecimal
  window.baseUrl = '/jsjldp/'
  // window.apiUrl = 'https://bda.szns.edu.cn/'
  window._post = _post

  // window.devUrl = ''
})()
